import {message, Tabs} from 'antd';
import React from 'react';
import {PageContainer} from '@ant-design/pro-layout';
import {isSuccess} from "@/utils/utils";
import {DesignerManager} from "@/services/api-functions";
import {SYS_ENUMS} from "@/utils/constants";
import ApplyDesignerList from "@/pages/user/designer/apply/list/component/ApplyDesignerList";

export const handleDesignerAudit = async (fields: any, select: any) => {
  if (!select) return false;
  try {
    if (isSuccess((await DesignerManager.designerAudit({
      businessId: select.id,
      auditOperate: fields.auditOperate,
      remark: fields.remark,
      flowType: 'DESIGNER_AUDIT'
    }))?.code)) {
      message.success(fields.auditOperate === SYS_ENUMS.RESOURCE_AUDIT_STATE.PASS.value ? '审核通过' : '审核拒绝');
      return true;
    }
    return false
  } catch (error) {
    return false;
  }
};

const DesignerApplyList: React.FC<any> = (props) => {

  return (
    <PageContainer>
      <Tabs destroyInactiveTabPane={true}>
        <Tabs.TabPane forceRender tab='定制设计师' key="CUSTOMIZE_DESIGNER">
          <ApplyDesignerList handleDesignerAudit={handleDesignerAudit} {...props} type='CUSTOMIZE'/>
        </Tabs.TabPane>
        <Tabs.TabPane forceRender tab='创作设计师' key="CREATE_DESIGNER">
          <ApplyDesignerList handleDesignerAudit={handleDesignerAudit} {...props} type='CREATE'/>
        </Tabs.TabPane>
      </Tabs>
    </PageContainer>
  );
};

export default DesignerApplyList;
